//设置html根目录字体大小
require(['jquery', '../modules/pageSize', '../modules/popup'], function ($, pageSetSize, popup) {
    setRootFontSize(pageSetSize);
    //评价状态 0:差评 1:好评
    var ctStatus = 0;
    $(".ev-comment .ctway i").on("click", function(){
        if(!$(this).hasClass("active")){
            $(this).addClass("active").siblings().removeClass("active");  
            ctStatus = $(this).hasClass("good") ? 1 : 0;
            //alert(ctStatus);
            $(this).parents(".evaluation-item").attr("data-ctway", ctStatus);
        }
    });
    $(".ev-stars").each(function(i, o){
        $(o).children('i').each(function(j, c){
            $(this).on("click", function(){
                var cparent = $(this).parents(".evaluation-item");
                if($(this).parent().hasClass('ev-goods-ct')){
                    cparent.attr("data-gdrank", j+1);
                }else{
                    cparent.attr("data-wlrank", j+1);
                }
                $(this).siblings().attr("class", "");
                $(this).attr("class", "").addClass("active");
                $(this).prevAll("i").attr("class", "").addClass("active");
            });
        });
    });

    var _isSaveComment = false;
    $(".save-comment a").click(function(){
        if(_isSaveComment){
            popup.alertPopup("不要重复提交！");
            return;
        }
        _isSaveComment = true;
        var rslist = [];
        $(".evaluation-item").each(function(){
            rslist.push({product_id: $(this).attr("data-id"), ctStatus: $(this).attr("data-ctway"), product_point: $(this).attr("data-gdrank"),
                logistics_point: $(this).attr("data-wlrank"), content: $(this).find(".ct-message").val()});
        });
        var data = {
            order_id : $('#order_id').val(),
            list: rslist
        };
        //console.log(data);return;
        $.ajax({
            type: "post",
            url: "/Home/Member/doMemberEvaluation"+getFixedExtraUrl(),
            data: data,
            dataType: "json",
            success: function (data) {
                popup.alertPopup(data.msg);
                if(data.stat){
                    setTimeout(function(){
                        window.location.href = '/Member/index'+getFixedExtraUrl();
                    },300);
                }

            },
            error: function () {
                _isSaveComment = false;
                popup.alertPopup('服务器异常，请稍后重试！');
            }
        });
    });
});